package com.lcifn.spring.aop.test.bcel;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.bcel.classfile.ClassFormatException;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.LocalVariable;
import org.apache.bcel.classfile.LocalVariableTable;
import org.apache.bcel.classfile.Method;

public class MethodNameResolve {

	public static void main(String[] args) throws ClassNotFoundException, ClassFormatException, IOException {
		//String className = "com.lcifn.spring.aop.advice.AspectJAnnotationArgsBrowserAroundAdvice";
		String className = "BcelDemo";
		String classFile = className.replace(".", "/");
		
		//InputStream is = MethodNameResolve.class.getClassLoader().getResourceAsStream(classFile + ".class");
		InputStream is = new FileInputStream(new File("C:/Users/meicai/Desktop/BcelDemo.class"));
		ClassParser classParser = new ClassParser(is, className);
		JavaClass javaClass = classParser.parse();
		//JavaClass lookupClass = Repository.lookupClass(AspectJAnnotationArgsBrowserAroundAdvice.class);
		Method[] methods = javaClass.getMethods();
		for(Method method : methods){
			//if(method.getName().equals("pointcut")){
				LocalVariableTable lvt = method.getLocalVariableTable();
				LocalVariable[] localVariables = lvt.getLocalVariableTable();
				for(LocalVariable lv : localVariables){
					System.out.println(lv.getNameIndex()+ ":" + lv.getName());
				}
			//}
		}
	}
}
